<?php
/**
 * +----------------------------------------------------------------------
 * | Copyright © Sogu Technologies Co. Ltd 2018-2050 All rights reserved.
 * +----------------------------------------------------------------------
 * | File name: CommonPlatformRequest.php
 * +----------------------------------------------------------------------
 * | Author:
 * +----------------------------------------------------------------------
 * | Description: 催收请求类
 * +----------------------------------------------------------------------
 * | Others: 其他内容的说明
 * +----------------------------------------------------------------------
 * | History: 修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简述
 * +----------------------------------------------------------------------
 * | 1.Date: 2018/12/25 Author: sam Modification: 创建
 * +----------------------------------------------------------------------
 */

namespace App\Library\Guzzle;

use App\Library\Traits\CollectionRequest as CollectionRequestTraits;

class CollectionRequest
{
    use CollectionRequestTraits;
    /**
     * 催收平台基础uri
     * @var \Illuminate\Config\Repository|mixed
     */
    protected $collection_uri;

    /** 推新案接口
     * @var string 传固定值: weijie
     */
    protected $collection_org_code;

    /**
     *推送新案件的接口
     * @var string
     */
    protected $send_new_case = '/api/new/case';

    /**
     *更新案件的接口
     * @var string
     */
    protected $send_update_case = '/api/update/case';

    /**
     *推送还款接口,用于推送已经分配的案件的还款信息,此接口实时调用
     * @var string
     */
    protected $send_new_repay = '/api/new/repay';

    /**
     *APP客户主动发起还款,请求催收系统
     * @var string
     */
    protected $send_active_deduction = 'api/repay/record';

    /**
     * 代扣,销账,全部结清的回执接口
     * @var string
     */
    protected $send_receipt = '/api/apply/back';

    /**
     * 公共请求参数
     * @var array
     */
    protected $body = [];

    /**
     * 参数集合
     * @var array
     */
    private $_pub_data;

    /**
     * 业务数据签名
     * @var string
     */
    private $_pub_sign;

    /**
     * CommonPlatformRequest constructor.
     */
    public function __construct()
    {
        $this->collection_uri = config('common.collection_base_uri');
        $this->collection_org_code = config('common.collection_org_code');
    }

    /**
     * Description: 催收推新案件
     * Author: Gxs
     * @param array $req_data
     * @return mixed
     */
    public function sendNewCase($req_data)
    {
        $this->_pub_data = $req_data;
        $this->_pub_sign = Sign::collectionSign($this->_pub_data);
        $url = $this->send_new_case;
        return $this->request($url);
    }

    /**
     * Description: 催收更新案件
     * Author: Gxs
     * @param array $req_data
     * @return mixed
     */
    public function sendUpdateCase(array $req_data)
    {
        $this->_pub_data = $req_data;
        $this->_pub_sign = Sign::collectionSign($this->_pub_data);
        $url = $this->send_update_case;
        return $this->request($url);
    }

    /**
     * Description: 催收系统分案后更新案件信息
     * Author: Gxs
     * @param array $caseMsg
     * @param array $repayRecord
     * @param array $repayPlanList
     * @return mixed
     */
    public function sendRepayMentCase(array $caseMsg, array $repayRecord, array $repayPlanList)
    {
        $this->_pub_data = [
            'caseMsg' => $caseMsg,
            'repayRecord' => $repayRecord,
            'repayPlanList' => $repayPlanList,
        ];
        $this->_pub_sign = Sign::collectionSign($this->_pub_data);
        $url = $this->send_new_repay;
        return $this->request($url);
    }

    /**
     * Description:
     * Author:zhaiyukang
     *
     * @param array $deduction
     * @return mixed
     */
    public function sendActiveDeductionCase(array $deduction)
    {
        $this->_pub_data = $deduction;
        $this->_pub_sign = Sign::collectionSign($this->_pub_data);
        $url = $this->send_active_deduction;
        return $this->request($url);
    }

    public function sendReceipt(array $data){
        \Log::debug($data);
        $this->_pub_data = [
            'caseCode' => $data['caseCode'],
            'type' => $data['type'],
            'applyNumber' => $data['applyNumber'],
            'state' => $data['state'],
            'message' => $data['message'],
        ];
        $this->_pub_sign = Sign::collectionSign($this->_pub_data);
        $url = $this->send_receipt;
        return $this->request($url);
    }
}